package net.wang.staffing_system.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

/**
 *
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {

    @GetMapping(value = "/exception")
    public void testExceptionHandler() throws Exception {
        throw new Exception("全局异常");
    }

    @GetMapping(value = "/runtime/exception")
    public void testRuntimeExceptionHandler() throws RuntimeException {
        throw new RuntimeException("运行时异常");
    }

    @GetMapping(value = "/sql/exception")
    public void testSQLExceptionHandler() throws SQLException {
        throw new SQLException("数据库异常");
    }

    @GetMapping(value = "/io/exception")
    public void testIOExceptionHandler() throws IOException {
        throw new IOException("IO异常");
    }

    @GetMapping(value = "/ok")
    public Object testNormal() {
        System.out.println("ok");
        return "OK";
    }

    @PostMapping(value = "/excel")
    public String uploadFile(MultipartFile file) {

        System.out.println(file.getName());
        File f = new File("E:\\Servers\\tomcat_file\\webapps");
        if (!f.exists()) {
            f.mkdirs();
        }

        return "Ok";

    }
}
